<script lang="ts" setup>
import type { FormInstance } from '@arco-design/web-vue'
// import type { DomainItem } from '@/apis/model/resolve'

const props = withDefaults(defineProps<IProp>(), {})
// import { marked } from 'marked'
const emit = defineEmits(['reload'])
const text = ref<string>('')
// import { v4 as uuidV4 } from 'uuid'
interface IProp {
  record?: any
}
// 上传的文件
const uploadFile = ref<File>()

// const isUnClick = ref(true)
const loading = ref<boolean>(false)
const fileList = ref<any[]>([])
const formRef = ref<FormInstance>()
const formState = ref({
  imprint: '',
  version: '',
  file_key: '',
  file: undefined,
  id: undefined,
})
// 清空表单
function resetField() {
  formRef.value?.resetFields()
  formState.value = {
    imprint: '',
    version: '',
    file_key: '',
    file: undefined,
    id: undefined,
  }
  fileList.value = []
  uploadFile.value = undefined
}

const visible = defineModel<boolean>('visible', { required: true })
// const emit = defineEmits(['reload'])

// const markdownContent = ref('')
async function handleOpen() {
  text.value = props.record?.imprint || ''
  // markdownContent.value = marked(props.record?.imprint || '')
}
async function handleSubmit() {
  // const error = await formRef.value?.validate()
  // if (error) return false
  // const fn = props.record ? updateApiResolveDomainApi : addApiResolveDomainApi
  // const data = props.record
  //   ? { id: props.record.id!, ...formState.value }
  //   : formState.value
  // return fn(data).then(() => {
  //   Message.success(msg)
  //   emit('reload')
  // })
}

function handleClose() {
  resetField()
  emit('reload')
  visible.value = false
}
</script>

<template>
  <resource-dialog
    v-model:visible="visible"
    :loading="loading"
    title="版本说明"
    :width="480"
    :mask-closable="false"
    :before-ok="handleSubmit"
    :footer="false"
    :before-open="handleOpen"
    :before-close="handleClose"
  >
    <div class="imprint-detail">
      <div
        style="white-space: pre-wrap"
        v-html="text"
      />
    </div>
    <!-- <a-textarea
      v-model="text"
      disabled
      :auto-size="{ maxRows: 18, minRows: 18 }"
    /> -->
  </resource-dialog>
</template>

<style scoped lang="less">
:deep(.arco-textarea) {
  -webkit-text-fill-color: #393c40;
}
.imprint-detail {
  color: var(--text-1, #1d2129);
  /* regular/12 */
  font-family: 'Microsoft YaHei UI';
  font-size: 12px;
  font-style: normal;
  font-weight: 400;
  line-height: normal;
  height: 320px;
  overflow-x: hidden;
  overflow-y: auto;
}
</style>
